#!/usr/bin/python3
# @Time    : 2024-03-22 上午 10:45
# @Author  : MingYangHe
# @Email   : 1780040868@qq.com

class MyLinkedList:

    def __init__(self):
        self.list = []

    def get(self, index: int) -> int:
        if 0 <= index < len(self.list):
            return self.list[index]
        else:
            return -1

    def addAtHead(self, val: int) -> None:
        self.list.insert(0, val)

    def addAtTail(self, val: int) -> None:
        self.list.append(val)

    def addAtIndex(self, index: int, val: int) -> None:
        n = len(self.list)
        if index > n:
            return
        elif index == n:
            self.list.append(val)
        else:
            self.list.insert(index, val)

    def deleteAtIndex(self, index: int) -> None:
        if 0 <= index < len(self.list):
            del self.list[index]

    def printList(self) -> None:
        print(self.list)


myLinkedList = MyLinkedList()
myLinkedList.printList()

myLinkedList.addAtHead(1)
myLinkedList.printList()

myLinkedList.addAtTail(3)
myLinkedList.printList()  # 输出 [1, 3]

myLinkedList.addAtIndex(1, 2)  # 链表变为 1->2->3
myLinkedList.printList()  # 输出 [1, 2, 3]

print(myLinkedList.get(1))  # 返回 2

myLinkedList.deleteAtIndex(1)  # 现在，链表变为 1->3
myLinkedList.printList()  # 输出 [1, 3]

print(myLinkedList.get(1))  # 返回 3
